<?php
namespace App\Http\Controllers\Gateway;

use App\Http\Controllers\Controller;
use App\Lib\PaymentMap;
use App\Models\OrderQrcode;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class QrcodeShowController extends Controller
{
    public function show(Request $request, $plat_no)
    {
        $redisData = Redis::get('qrcode:'.$plat_no);
        if ( ! $redisData) {
            return view('gateway.recharge.expired');
        }
        $redisData = json_decode($redisData, true);
        $orderInfo = $redisData['orderInfo'];

        $qrCode = $redisData['qrCode'];
        $mchData = $orderInfo['order_data'];
        $view = '';
        if ($mchData['recharge_type'] == PaymentMap::WX) {
            $view = 'gateway.recharge.qrCode.wx';
        } elseif ($mchData['recharge_type'] == PaymentMap::ALI) {
            $view = 'gateway.recharge.qrCode.ali';
        } elseif ($mchData['recharge_type'] == PaymentMap::QQ) {
            $view = 'gateway.recharge.qrCode.qq';
        }
        return view($view, [
            'qrCode' => $qrCode,
            'order' => $orderInfo
        ]);

    }
}
